package br.inf.solutions.apresentacoes.ssp.view.composer.hierarchy;

import org.springframework.context.annotation.Scope;
import org.zkoss.zk.ui.Component;

import br.com.vexillum.util.Message;
import br.com.vexillum.util.Return;
import br.inf.solutions.apresentacoes.ssp.model.hierarchy.HierarchyStructEntity;
import br.inf.solutions.apresentacoes.ssp.view.composer.FunctionPersonComposer;

@SuppressWarnings("serial")
@org.springframework.stereotype.Component
@Scope("prototype")
public class FunctionPersonHierarchyComposer extends HierarchyStructEntityComposer {

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		loadBinder();
	}

	public Return selectUnityInHierarchy() {
		Return ret = new Return(true);
		FunctionPersonComposer parent = (FunctionPersonComposer) arg
				.get("thisComposer");
		if (parent != null) {
			HierarchyStructEntity unity = (HierarchyStructEntity) getTreeStructure()
					.getSelectedItem().getValue();
			if (unity == null) {
				ret.setValid(false);
				ret.addMessage(new Message(null,
						getMessage("hierarchy_selectedunityentity_false")));
			}
			if (unity.getType().getName().equals("Unidade")) {
				parent.setUnitDestiny(unity);
				parent.loadBinder();
				getComponentById("treeModalWindow").detach();
				parent.loadListFunctions();
			} else {
				ret.setValid(false);
				ret.addMessage(new Message(null,
						getMessage("hierarchy_selectedisunity_false")));
			}
		}
		return ret;
	}
}
